package com.gmrz.uap.util;

import java.io.*;

/**
 * Created by ouhouki on 16/9/5.
 */
public class IOUtils {
    /**
     * 将字符串数据写到指定文件中
     * @param data        字符串
     * @param targetFile  目标文件
     */
    public static void String2File(String data, File targetFile){
        BufferedReader bfr = null;
        BufferedWriter bfw = null;
        try {
            bfr = new BufferedReader(new StringReader(data.toString()));
            bfw = new BufferedWriter(new FileWriter(targetFile));
            String len = null;
            while ((len=bfr.readLine())!=null){
                bfw.write(len);
                bfw.newLine();
            }
        } catch (IOException e) {
        }finally {
            if (bfr!=null)
                try {
                    bfr.close();
                } catch (IOException e) {
                }
            if (bfw!=null)
                try {
                    bfw.close();
                } catch (IOException e) {
                }
        }
    }
}
